package com.techblor.lock.library.config;

import com.techblor.lock.library.RedLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * redis library自动装配配置类
 */
@Configuration
@ComponentScan(basePackages = "com.techblor")
@ConditionalOnClass({RedLockAutoConfiguration.class})
@ConditionalOnProperty(prefix = "spring.redis", name = "enable", matchIfMissing = true)
public class RedLockAutoConfiguration {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Bean
    public RedLock redLock() {
        return new RedLock(redisTemplate);
    }
}
